<?php


namespace App\Models\AdminUser;


use App\Commons\Utils\ModelTools\BaseModel;
use Illuminate\Support\Facades\Hash;

class User extends BaseModel {
    protected $dateFormat = 'Y-m-d H:i:s';

    protected $searchable = [
        'id',
        'name',
        'email',
        'mobile',
        'type',
        'created_at',
    ];

    protected $casts = [
        'type'           => 'integer',
        'wx_template_id' => 'integer',
    ];

    protected $hidden = [
        'password'
    ];

    //是否删除
    const DELETED_NO  = 0;
    const DELETED_YES = 1;

    //用户类型,1信雅超级管理员 2开发人员 3 普通用户
    const USER_TYPE_SUPER      = 1;
    const USER_TYPE_DEVELOPERS = 2;
    const USER_TYPE_NORMAL     = 3;
    
    /**
     * status 状态， 1:启用，0：禁用
     */
    const STATUS_NO  = 0;
    const STATUS_YES = 1;

    /**
     * @param $query
     * @return mixed
     */
    public function scopeNoDeleted($query) {
        return $query->where('deleted', self::DELETED_NO);
    }

    /**
     * password
     * @param $val
     */
    public function setPasswordAttribute($val) {
        $this->attributes['password'] = Hash::make($val);
    }
}